#ifndef __NET_H__
#define __NET_H__

#include <stdio.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <strings.h>
#include "mxml.h"

#define UNIX_PATH "/tmp/unix.str"

enum NETTYPE
{
    NET_MEGAEYES = 'A',
    NET_CLIENT,
	NET_VOICE_MEGAEYES,
	NET_VOICE_CLIENT
};

typedef struct _VSP_SENDER_HEADER
{
	int version;
	int xmlLen;
	int cmdCode;
	int cmdSeq;
	char srcID[32];
	char dstID[32];
}VSP_SNDHEADER;

typedef struct _VSP_RECEIVER_HEADER
{
	int version;
	int xmlLen;
	int cmdCode;
	int cmdSeq;
	int flags; //default flags = 0
}VSP_RECVHEADER;

struct net_no{
	unsigned char	levelNO[8];
	unsigned char	deviceNO[2];
	unsigned char	deviceType;
};
typedef struct net_no NET_NO;

/*command message struct*/
typedef struct{
	unsigned char	startFlagFirst;
	unsigned char	startFlagSecond;
	unsigned char	startFlagThird;
	unsigned char	startFlagFourth;
} MSG_START_FLAG;/*flag*/

struct msg_head{
	unsigned char   msgLengthLow;
	unsigned char   msgLengthHigh;
	NET_NO		dstNetNo;
	NET_NO		srcNetNo;
	unsigned char	msgType;
	unsigned char   msgSeqNumLow;
	unsigned char   msgSeqNumHigh;
	unsigned char   msgSerNumLow;
	unsigned char   msgSerNumHigh;
};

typedef struct msg_head  MSG_HEAD; /*message head struct*/
typedef	struct{
	MSG_START_FLAG	msgStartFlag;
	MSG_HEAD        msgHead;
	unsigned char	msgContent[1450];
}MSG_TOTAL_DATA;/*message struct*/

ssize_t write_fd(int fd, void *ptr, size_t nbytes, int sendfd);

ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd);


//int NetSendSocketFd(int sendfd,enum NETTYPE nettype);
int NetSendSocketFd(int sendfd,enum NETTYPE nettype,char* cmd_buff,int cmd_len);


VSP_RECVHEADER InitVSP_RECVHeader(int len, int code, int seq, int flags );

/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  set scoket options
 * 
 * @Param sockfd
 */
/* ----------------------------------------------------------------------------*/
void SetSockOptions(int fd);

#endif

